package practica8;

import java.io.*;

import org.antlr.*;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;


public class Procesador 
{
	public static void main(String args[]) throws IOException, RecognitionException {
		try {
			CharStream cs = new ANTLRFileStream(args[0]);
			CommonTokenStream tokens = new CommonTokenStream();
	        
			if (args[0].endsWith(".txt")) {		        
				ExpresionesLexer analex = new ExpresionesLexer(cs);
		        tokens.setTokenSource(analex);
//		        System.out.println(tokens);
		        ExpresionesParser anasint = new ExpresionesParser(tokens);
		        anasint.entrada();
			}
			
			else if (args[0].endsWith(".c")) {
				CodigoCLexer analex = new CodigoCLexer(cs);
		        tokens.setTokenSource(analex);
//		        System.out.println(tokens);
		        CodigoCParser anasint = new CodigoCParser(tokens);
		        System.out.println(anasint.entrada());
			}
			
			else if (args[0].endsWith(".xml")) {
				CodigoXMLLexer analex = new CodigoXMLLexer(cs);
		        tokens.setTokenSource(analex);
//		        System.out.println(tokens);
		        CodigoXMLParser anasint = new CodigoXMLParser(tokens);
		        anasint.elementos();
			}
			
			else if (args[0].endsWith(".java")) {
				BreakLexer analex = new BreakLexer(cs);
		        tokens.setTokenSource(analex);
//		        System.out.println(tokens);
		        BreakParser anasint = new BreakParser(tokens);
		        anasint.entrada(false);
			}
		}
		catch(IOException ioe) {
			System.err.println(ioe.getMessage());
		}
	}
}
